require(["footballblog/FootballblogApiClient", "dojo/parser", "dijit/form/TextBox", "dijit/Editor", "dijit/_editor/plugins/TextColor", "dijit/form/Button", 
         "dojo/dom", "dojo/dom-attr", "dojo/on"], 
		function(FootballblogApiClient, parser, textbox, Editor, textcolor, button, dom, domattr, on){
	
	parser.parse();
	var articleEditor = new Editor({
		extraPlugins: ['foreColor']
	}, dom.byId("articleContent"));
	
	on(dom.byId("formButton"), "click", function(evt){
		console.log("in very new onSubmitArticle inline function");		
		var authorType = domattr.get(dom.byId("authorType"), "value");
		var authorExternalId = domattr.get(dom.byId("authorExternalId"), "value");
		var authorName = domattr.get(dom.byId("authorName"), "value");
		var authorScreenName = domattr.get(dom.byId("authorScreenName"), "value");
		var authorPicUrl = domattr.get(dom.byId("authorPicUrl"), "value");
		var authorBigPicUrl = domattr.get(dom.byId("authorBigPicUrl"), "value");
		var authorMiniPicUrl = domattr.get(dom.byId("authorMiniPicUrl"), "value");			
		var articleTitle = domattr.get(dom.byId("articleTitle"), "value");
		var articleContent = articleEditor.get("value");
				
		var apiClient = new FootballblogApiClient();
		apiClient.isSync = false;
		apiClient.postAuthor(authorType, authorExternalId, authorName, authorScreenName, authorPicUrl, authorBigPicUrl, authorMiniPicUrl, 
				function(authorId){
					console.log("the real author id back in the main thread is:" + authorId);
					apiClient.postArticle(authorId, articleTitle, articleContent, function(articleId){
				dom.byId("articleId").innerHTML = articleId;	
			});
		});	
	});
});

